/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yy.bugzillahelp;

import com.yy.bugzillahelp.action.download.BugCrawlAction;
import com.yy.bugzillahelp.data.server.ServerData;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hualun-alan
 */
public class Test {

    public static String getXMLById(ServerData connectData, int id) {
        StringBuilder sb = new StringBuilder();
        try {
            URL jspURL = new URL(connectData.getServerUrl() + "/show_bug.cgi?id=100,101,102&ctype=xml");
            System.out.println(jspURL);
            URLConnection urlCon = (URLConnection) jspURL.openConnection();
            urlCon.setUseCaches(false);
            InputStream inputStream = urlCon.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String line = br.readLine();
            while (line != null) {
                if (!line.contains("DOCTYPE") && !line.trim().isEmpty()) {
                    sb.append(line).append("\n");
                }
                line = br.readLine();
            }
            br.close();
            inputStream.close();
        } catch (IOException ex) {
            Logger.getLogger(BugCrawlAction.class.getName()).log(Level.SEVERE, null, ex);
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(getXMLById(MainFrame.CONNECT_DATA, 1));
    }
}
